package com.lxq.ware.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.lxq.ware.entity.vo.MergeVo;
import com.lxq.ware.entity.vo.PurchaseDoneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lxq.ware.entity.PurchaseEntity;
import com.lxq.ware.service.PurchaseService;
import com.lxq.common.utils.PageUtils;
import com.lxq.common.utils.ResponseModel;



/**
 * 采购信息
 *
 * @author lxq
 * @email xiaoqiu9099@163.com
 * @date 2021-09-03 12:00:33
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 完成采购单
     * @param doneVo
     * @return
     */
    @PostMapping(value = "/done")
    public ResponseModel finish(@RequestBody PurchaseDoneVo doneVo) {

        purchaseService.done(doneVo);

        return ResponseModel.ok();
    }

    /**
     * 领取采购单
     * @param ids
     * @return
     */
    @PostMapping(value = "/received")
    public ResponseModel received(@RequestBody List<Long> ids) {

        purchaseService.received(ids);

        return ResponseModel.ok();
    }

    /**
     * 合并整单
     * @param mergeVo
     * @return
     */
    ///ware/purchase/merge
    @PostMapping(value = "/merge")
    public ResponseModel merge(@RequestBody MergeVo mergeVo) {

        purchaseService.mergePurchase(mergeVo);

        return ResponseModel.ok();
    }

    @GetMapping(value = "/unreceive/list")
    public ResponseModel unreceiveList(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPageUnreceive(params);

        return ResponseModel.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("ware:purchase:list")
    public ResponseModel list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return ResponseModel.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("ware:purchase:info")
    public ResponseModel info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return ResponseModel.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("ware:purchase:save")
    public ResponseModel save(@RequestBody PurchaseEntity purchase){
        Date date = new Date();
        purchase.setCreateTime(date);
        purchase.setUpdateTime(date);
		purchaseService.save(purchase);

        return ResponseModel.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("ware:purchase:update")
    public ResponseModel update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return ResponseModel.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("ware:purchase:delete")
    public ResponseModel delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return ResponseModel.ok();
    }

}
